package com.coupon.controller;

import com.alibaba.fastjson.JSON;
import com.coupon.entity.TblUserCoupon;
import com.coupon.entity.TblUserCoupon1;
import com.coupon.service.TblUserCouponService;
import com.coupon.util.Response_Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/couponAdmin")
public class TblUserCouponController {

    @Autowired
    private TblUserCouponService tblUserCouponService;

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @RequestMapping("list")
    public String listAll(int page, int limit, @RequestParam(defaultValue = "") String phoneNumber) {
        Response_Data responseData = tblUserCouponService.listAll(page, limit, phoneNumber);
        return JSON.toJSONString(responseData);
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回记录，没有返回null
     */
    @RequestMapping("getById")
    public String getById(@RequestParam int id) {
        Response_Data responseData = tblUserCouponService.getById(id);
        return JSON.toJSONString(responseData);
    }

    /**
     * 新增，忽略null字段
     *
     * @param tblUserCoupon 新增的记录
     * @return 返回影响行数
     */
    @RequestMapping("insert")
    public int insert(@RequestBody TblUserCoupon tblUserCoupon) {
        return tblUserCouponService.insertIgnoreNull(tblUserCoupon);
    }

    /**
     * 修改，忽略null字段
     *
     * @param tblUserCoupon 修改的记录
     * @return 返回影响行数
     */
    @RequestMapping("update")
    public String update(TblUserCoupon1  tblUserCoupon) {
        System.err.println(tblUserCoupon);
        Response_Data responseData = tblUserCouponService.update(tblUserCoupon);
        return JSON.toJSONString(responseData);
    }


    /**
     * 删除记录
     *
     * @param id 待删除的记录
     * @return 返回影响行数
     */
    @RequestMapping("delete")
    public int delete(int id) {
        return tblUserCouponService.delete(id);
    }


    @RequestMapping("getByDate")
    public String getByDate(@RequestParam int id) {
        Response_Data responseData = tblUserCouponService.getByDate(id);
        return JSON.toJSONString(responseData);
    }
}